import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import Layout from '@/layout/index.vue'

export const constantRoutes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: { hidden: true },
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: { title: '数据总览', icon: '' },
      },
    ],
  },

  // --- 订单管理模块 ---
  {
    path: '/order',
    component: Layout,
    redirect: '/order/reservation',
    name: 'Order',
    meta: { title: '订单管理', icon: '' },
    children: [
      {
        path: 'reservation',
        name: 'ReservationList',
        // 路径更新
        component: () => import('@/views/order/reservation/index.vue'),
        meta: { title: '预约信息', icon: '' },
      },
      {
        path: 'history',
        name: 'OrderHistory',
        component: () => import('@/views/order/history/index.vue'),
        meta: { title: '历史订单', icon: '' },
      },
    ],
  },

  // --- 设备管理模块 ---
  {
    path: '/device',
    component: Layout,
    redirect: '/device/list',
    name: 'Device', // 给父级也加上 name
    meta: { title: '设备管理', icon: '' },
    children: [
      {
        path: 'list',
        name: 'DeviceList',
        component: () => import('@/views/device/list/index.vue'),
        meta: { title: '设备列表', icon: '' },
      },
      {
        path: 'status',
        name: 'DeviceStatus',
        // 路径更新
        component: () => import('@/views/device/status/index_temp.vue'),
        meta: { title: '设备状态监控', icon: '' },
      },
    ],
  },

  // --- 系统管理模块 ---
  {
    path: '/system',
    component: Layout,
    redirect: '/system/carousel',
    name: 'System',
    meta: { title: '系统管理', icon: '' },
    children: [
      {
        path: 'carousel',
        name: 'SystemCarousel',
        component: () => import('@/views/system/carousel/index.vue'),
        meta: { title: '轮播图管理', icon: '' },
      },
      {
        path: 'content',
        name: 'SystemContent',
        component: () => import('@/views/system/content/index.vue'),
        meta: { title: '内容管理', icon: '' },
      },
    ],
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: constantRoutes,
})

export default router
